import { setupLayouts } from 'virtual:meta-layouts'
import generatedRoutes from 'virtual:generated-pages'
import type { RouteRecordRaw } from 'vue-router'
import subject from './modules/subject'
import RetailOrder from './modules/retail.order'
import RetailOrderYeji from './modules/RetailOrderYeji'
import refundApply from './modules/refund.apply'
import ProductRelease from './modules/product.release'
import MerchandiseControl from './modules/merchandise.control'
import videoManagement from './modules/video.management'
import barrageManagement from './modules/barrage.management'
import messageGroup from './modules/message.group'
import shareCard from './modules/share.card.configuration'
import clientAccount from './modules/client.account'
import weibanuser from './modules/weibanuser'
import pintuan from './modules/pintuan'
import yuanjiang from './modules/yuanjiang'
import aftersales from './modules/aftersales'
import indexact from './modules/indexact'
import skincheck from './modules/skincheck'
import skincheckTicket from './modules/skincheckTicket'
import screenCode from './modules/screenCode'
import sysshareconfig from './modules/sysshareconfig'
import skincheckLlksent from './modules/skincheckLlksent'
import clientAdminAccount from './modules/client.admin.account'
import clientAccountLabel from './modules/client.account.label'
import PeopleManagement from './modules/people.management'
import brandofficial from './modules/brandofficial'
import brandofficialAccount from './modules/brandofficialAccount'
import xiaohongshu from './modules/cid.xiaohongshu'
import vipgift from './modules/vipgift'
import living from './modules/living'
import vipcenterpage from './modules/vipcenterpage'
import music from './modules/music'
import store from './modules/store'
import drawact from './modules/draw'
import postage from './modules/postage'
import givefacialmaskact from './modules/givefacialmaskact'
import collection from './modules/collection'
import fukaact from './modules/fukaact'
import renxuan from './modules/renxuan'
import tuangou from './modules/tuangou'
import freetrial from './modules/freetrial'
import birthday from './modules/birthday'
import memberholiday from './modules/memberholiday'
import signintask from './modules/signintask'
import subscriber from './modules/subscriber'
import membersignin from './modules/membersignin'
import hexiao from './modules/hexiao'
import hexiaoUser from './modules/hexiaoUser'
import shop from './modules/shop'
import recommenderconfig from './modules/recommenderconfig'
import account from './modules/account'
import performance from './modules/performance'
import statisticis from './modules/statisticis'
import icon from './modules/icon'
import vipIcon from './modules/vipIcon'
import screen from './modules/screen'
import voucher from './modules/voucher'
import membership from './modules/membership'
import memberscore from './modules/memberscore'
import memberscoreexchange from './modules/memberscoreexchange'
import subscribermsgtemple from './modules/subscribermsgtemple'
import subscribermsguser from './modules/subscribermsguser'
import manor from './modules/manor'
import memberlevels from './modules/memberlevels'
import memberproduct from './modules/memberproduct'
import productshare from './modules/productshare'
import homePage from './modules/home.page'
import type { Route } from '#/global'
import { $t } from '@/locales'
import pinia from '@/store'
import useSettingsStore from '@/store/modules/settings'
// 固定路由（默认路由）
const constantRoutes: RouteRecordRaw[] = [
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login.vue'),
    meta: {
      whiteList: true,
      title: $t('route.login'),
    },
  },
  {
    path: '/:all(.*)*',
    name: 'notFound',
    component: () => import('@/views/404.vue'),
    meta: {
      title: '找不到页面',
    },
  },
]

// 系统路由
const systemRoutes: RouteRecordRaw[] = [
  {
    path: '/',
    name: 'home',
    component: () => import('@/layouts/index.vue'),
    meta: {
      breadcrumb: false,
    },
    children: [
      {
        path: '',
        component: () => import('@/views/index.vue'),
        meta: {
          title: $t(useSettingsStore(pinia).settings.home.title),
          icon: 'i-ant-design:home-twotone',
          breadcrumb: false,
        },
      },
      {
        path: 'reload',
        name: 'reload',
        component: () => import('@/views/reload.vue'),
        meta: {
          title: '重新加载',
          breadcrumb: false,
        },
      },
      {
        path: 'personal/notification',
        name: 'personalNotification',
        component: () => import('@/views/personal/notification.vue'),
        meta: {
          title: $t('route.personal.notification'),
        },
      },
    ],
  },
]

// 动态路由（异步路由、导航栏路由）
const asyncRoutes: Route.recordMainRaw[] = [
  {
    meta: {
      title: '商品&订单',
      icon: 'icon-park-solid:commodity',
    },
    children: [
      subject,
      ProductRelease,
      MerchandiseControl,
      voucher,
      RetailOrder,
      aftersales,
      RetailOrderYeji,
      refundApply,
      hexiao,
      hexiaoUser,
      postage,
      store,
      pintuan,
    ],
  },
  {
    meta: {
      title: '推荐官',
      icon: 'material-symbols:recommend-outline',
    },
    children: [
      shop,
      account,
      performance,
      statisticis,
      recommenderconfig,
    ],
  },
  {
    meta: {
      title: '会员系统',
      icon: 'mdi:math-integral-box',
    },
    children: [
      memberscore,
      memberscoreexchange,
      membership,
      memberlevels,
      memberproduct,
      membersignin,
      yuanjiang,
    ],
  },
  {
    meta: {
      title: '活动管理',
      icon: 'la:gifts',
    },
    children: [
      drawact,
      givefacialmaskact,
      freetrial,
      birthday,
      memberholiday,
      collection,
      fukaact,
      renxuan,
      tuangou,
      signintask,
    ],
  },
  {
    meta: {
      title: '投放&落地',
      icon: 'ic:baseline-pageview',
    },
    children: [
      videoManagement,
      barrageManagement,
      xiaohongshu,
    ],
  },
  {
    meta: {
      title: '私域',
      icon: 'ix:zone',
    },
    children: [
      clientAccount,
      clientAdminAccount,
      clientAccountLabel,
      shareCard,
      messageGroup,
      weibanuser,
      skincheck,
      skincheckTicket,
      skincheckLlksent,
      screen,
      screenCode,
    ],
  },
  {
    meta: {
      title: '小程序',
      icon: 'icon-park-outline:weixin-mini-app',
    },
    children: [
      homePage,
      indexact,
      manor,
      vipcenterpage,
      music,
      icon,
      vipIcon,
      vipgift,
      subscribermsgtemple,
      subscribermsguser,
      subscriber,
      living,
      sysshareconfig,
      brandofficial,
      brandofficialAccount,
      productshare,
    ],
  },
  {
    meta: {
      title: '系统',
      icon: 'ic:outline-settings',
    },
    children: [
      PeopleManagement,
    ],
  },
]

const constantRoutesByFilesystem = generatedRoutes.filter((item) => {
  return item.meta?.enabled !== false && item.meta?.constant === true
})

const asyncRoutesByFilesystem = setupLayouts(generatedRoutes.filter((item) => {
  return item.meta?.enabled !== false && item.meta?.constant !== true && item.meta?.layout !== false
}))

export {
  constantRoutes,
  systemRoutes,
  asyncRoutes,
  constantRoutesByFilesystem,
  asyncRoutesByFilesystem,
}
